#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:fight.py
# author:wmf
# datetime:2021/4/17 21:13
# software: PyCharm
'''
this is function description
'''
# import module your need


from DOG import Dog
from PEOPLE import People
from random import randint


class fight:

    def __init__(self, the_dogs, the_humans):
        self.dogs = the_dogs
        self.humans = the_humans

    def win_judge(self):
        for x in self.dogs:
            if x.life <= 0:
                self.dogs.pop(dogs.index(x))
                print("%s被击败了" % x.name)
        for x in self.humans:
            if x.life <= 0:
                self.humans.pop(humans.index(x))
                print("%s被击败了" % x.name)
        if len(self.dogs) == 0:
            print("人类胜利")
            return 0
        elif len(self.humans) == 0:
            print("狗胜利")
            return 0

    def start_fight(self):
        dog_attack = 0
        people_attack = 0
        x = randint(0, 1)
        if x == 0:
            print("狗先攻击")
            round_turn = [1]
            while True:
                if self.win_judge() != 0:
                    print("第%d回合" % round_turn[0])
                    if round_turn[0] % 2 == 1:
                        for y in self.dogs:
                            if dog_attack <= y.attack:
                                dog = y
                                dog_attack = y.attack
                        z = randint(0, len(self.humans) - 1)
                        dog.make_hurt(self.humans[z])
                        round_turn[0] = round_turn[0] + 1
                    else:
                        for y in self.humans:
                            if people_attack <= y.attack:
                                people = y
                                people_attack = y.attack
                        z = randint(0, len(self.dogs) - 1)
                        people.make_hurt(self.dogs[z])
                        round_turn[0] = round_turn[0] + 1
                else:
                    break
        else:
            print("人先攻击")
            round_turn = [1]
            while True:
                if self.win_judge() != 0:
                    print("第%d回合" % round_turn[0])
                    if round_turn[0] % 2 == 1:
                        for y in self.humans:
                            if people_attack <= y.attack:
                                people = y
                                people_attack = y.attack
                        z = randint(0, len(self.dogs) - 1)
                        people.make_hurt(self.dogs[z])
                        round_turn[0] = round_turn[0] + 1
                    else:
                        for y in self.dogs:
                            if dog_attack <= y.attack:
                                dog = y
                                dog_attack = y.attack
                        z = randint(0, len(self.humans) - 1)
                        dog.make_hurt(self.humans[z])
                        round_turn[0] = round_turn[0] + 1
                else:
                    break


d1 = Dog("Schnauzer")
d2 = Dog("Husky")
d3 = Dog("Teddy")
dogs = [d1, d2, d3]
p1 = People("Adam")
p2 = People("Eva")
humans = [p1, p2]
fighting = fight(dogs, humans)
fighting.start_fight()
